﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace SBLib.Common.ValidationKS
{
   public class ValidationFuncKS
    {
        /// <summary>
        /// Email validation
        /// </summary>
        public static bool ValidateEmail(string email)
        {
            bool valid = false;

            try
            {

                if (email.Trim().Length > 0)
                {
                    string regexPattern = @"^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(ad|aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$";

                    Regex re = new Regex(regexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(email.Trim());
                }
            }
            catch (Exception)
            {
                return false;
            }

            return valid;
        }


        /// <summary>
        /// Alphabet only validation
        /// </summary>
        public static bool ValidateAlphabetOnly(string textValue)
        {
            bool valid = false;

            try
            {
                if (textValue.Trim().Length > 0)
                {
                    string regexPattern = @"^[a-zA-Z\s]+$";

                    Regex re = new Regex(regexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(textValue.Trim());
                }
            }
            catch (Exception)
            {
                return false;
            }

            return valid;
        }

        /// <summary>
        /// Alphanumeric only validation
        /// </summary>
        public static bool ValidateAlphanumeric(string textValue)
        {
            bool valid = false;

            try
            {
                if (textValue.Trim().Length > 0)
                {
                    string regexPattern = @"^[a-zA-Z0-9\s.\-]+$";

                    Regex re = new Regex(regexPattern, RegexOptions.IgnoreCase);
                    valid = re.IsMatch(textValue.Trim());
                }
            }
            catch (Exception)
            {
                return false;
            }

            return valid;
        }

    }
}
